package convert

import (
	"context"
	"github.com/jinzhu/copier"

	"gitee.com/zy_blue7/db-convert-api/internal/svc"
	"gitee.com/zy_blue7/db-convert-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListLogic) List() (resp *types.DataConViewResp, err error) {
	// todo: add your logic here and delete this line

	var configs []types.DataConView
	for _, config := range l.svcCtx.DataConConfigs {
		var c types.DataConView
		copier.Copy(&c, &config)
		configs = append(configs, c)
	}

	return &types.DataConViewResp{
		Result: types.Result{
			Code:      200,
			Message:   "",
			ExtInfo:   "",
			Timestamp: 0,
		},
		DataConViews: configs,
	}, nil
}
